package org.examples.java.util.concurrent;

import static org.junit.Assert.assertEquals;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.junit.Test;

public class ExecutorTest {

	@Test
	public void testSingleThread() throws InterruptedException {
		Executor executor = Executors.newSingleThreadExecutor();
		final StringBuffer output = new StringBuffer();
		final CountDownLatch latch = new CountDownLatch(1);

		Runnable command1 = new Runnable() {
			@Override
			public void run() {
				output.append("Command1");
				latch.countDown();
			}
		};
		executor.execute(command1);
		latch.await();
		assertEquals("Command1", output.toString());
	}

}
